package com.dqyt.khjc.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * 时间工具类
 * 
 * @author Administrator
 *
 */
public class TimeUtil {

	/**
	 * 得到当前毫秒时间戳
	 * 
	 * @return
	 */
	public static long getCurrentTimeMillis() {
		return System.currentTimeMillis();
	}



	
	/**
	 * 获取当前时间(从1970到现在的毫秒)
	 */
	public static long currentTimeMillis() {
		return System.currentTimeMillis();
	}

	
	/**
	 * 毫秒数转 日期
	 * @param pattern  日期格式 如：2012-12-12 10:10
	 * @param dateTime 毫秒
	 * @return
	 */
	   public static String getFormatedDateTime(String pattern, long dateTime) {
	        SimpleDateFormat sDateFormat = new SimpleDateFormat(pattern);
	        return sDateFormat.format(new Date(dateTime + 0));
	    }
	   

	


	/**
	 * 格式化long型的时间12小时制(yyyy-MM-dd hh:MM:ss)
	 */
	public static String formatTime_One(long time) {
        //将指定时间(毫秒值)传给Date构造器，自动转换为日期，后面记得加上L
        Date date2 = new Date(time);
        //自己指定格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
        //输出结果为
        return dateFormat.format(date2);

	}


    /**
     * 格式化long型的时间12小时制(yyyy-MM-dd)
     */
    public static String formatTime_tow(long time) {
        //将指定时间(毫秒值)传给Date构造器，自动转换为日期，后面记得加上L
        Date date2 = new Date(time);
        //自己指定格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd");
        //输出结果为
        return dateFormat.format(date2);

    }


    /**
     * 格式化long型的时间12小时制(yyyy-MM-dd)
     */
    public static String formatTime_three(long time) {
        //将指定时间(毫秒值)传给Date构造器，自动转换为日期，后面记得加上L
        Date date2 = new Date(time);
        //自己指定格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/M-dd HH-mm-ss");
        //输出结果为
        return dateFormat.format(date2);

    }


    /**
     * 格式化long型的时间12小时制(yyyy-MM-dd)
     */
    public static String formatTime_Year(long time) {
        //将指定时间(毫秒值)传给Date构造器，自动转换为日期，后面记得加上L
        Date date2 = new Date(time);
        //自己指定格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");
        //输出结果为
        return dateFormat.format(date2);

    }


    /**
     * 格式化long型的时间12小时制(yyyy-MM-dd)
     */
    public static String formatTime_Month(long time) {
        //将指定时间(毫秒值)传给Date构造器，自动转换为日期，后面记得加上L
        Date date2 = new Date(time);
        //自己指定格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("MM");
        //输出结果为
        return dateFormat.format(date2);

    }

    /**
     * 格式化long型的时间12小时制(yyyy-MM-dd)
     */
    public static String formatTime_5(long time) {
        //将指定时间(毫秒值)传给Date构造器，自动转换为日期，后面记得加上L
        Date date2 = new Date(time);
        //自己指定格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("MM.dd");
        //输出结果为
        return dateFormat.format(date2);

    }


    /**
     * 格式化long型的时间12小时制(yyyy-MM-dd)
     */
    public static String formatTime_6(long time) {
        //将指定时间(毫秒值)传给Date构造器，自动转换为日期，后面记得加上L
        Date date2 = new Date(time);
        //自己指定格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日HH时mm分");
        //输出结果为
        return dateFormat.format(date2);

    }


	/**
	 * 得到今天0点0分0秒的时间
	 */
	public static long getCurrentDayZero() {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        return calendar.getTime().getTime();
	}


    /**
     *
     *
     * @return 当天的23:59:59 时间戳
     */
    public static long getTodayEndTime() {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        return calendar.getTime().getTime();
    }

	
	
	/**
	 * 获取当天零点的毫秒值并将时间格式化 
	 * @return
	 */
	public static long getTodayZero() {
	    Date date = new Date();     
	    long l = 24*60*60*1000; //每天的毫秒数 
	    //date.getTime()是现在的毫秒数，它 减去 当天零点到现在的毫秒数（ 现在的毫秒数%一天总的毫秒数，取余。），理论上等于零点的毫秒数，不过这个毫秒数是UTC+0时区的。 
	    //减8个小时的毫秒值是为了解决时区的问题。
	    return (date.getTime() - (date.getTime()%l) - 8* 60 * 60 *1000);
	}
	
	/**
	 * 获取当前日期
	 * @param format  日期格式
	 * @return
	 */
	public static String getNowDate(String format){
		SimpleDateFormat formatter = new SimpleDateFormat (format); 
		Date curDate = new Date(System.currentTimeMillis());//获取当前时间 
		String str = formatter.format(curDate);
		return str; 
	}
	
	/**
	 * 获取当前月份 返回英文 格式
	 * @param
	 * @return
	 */
	public static String getEnNowDate(){
		String month =getNowDate("MM");
		String month_en="";
		switch (Integer.parseInt(month)) {
		case 1:
			month_en="January";
			break;
		case 2:
			month_en="February";	
			break;
		case 3:
			month_en="March";
			break;
		case 4:
			month_en="April";
			break;
		case 5:
			month_en="May";
			break;
		case 6:
			month_en="June";
			break;
		case 7:
			month_en="July";
			break;
		case 8:
			month_en="August";
			break;
		case 9:
			month_en="September";
			break;
		case 10:
			month_en="October";
			break;
		case 11:
			month_en="November";
			break;
		case 12:
			month_en="December";
			break;
		}
		return month_en;
	}
	
	
	 /**
     * 描述：String类型的日期时间转化为Date类型.
     *
     * @param strDate String形式的日期时间
     * @param format  格式化字符串，如："yyyy-MM-dd HH:mm:ss"
     * @return Date Date类型日期时间
     */
    public static Date getDateByFormat(String strDate, String format) {
        SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
        Date date = null;
        try {
            date = mSimpleDateFormat.parse(strDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
    
    /**
     * 描述：Date类型转化为String类型.
     *
     * @param date   the date
     * @param format the format
     * @return String String类型日期时间
     */
    public static String getStringByFormat(Date date, String format) {
        SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
        String strDate = null;
        try {
            strDate = mSimpleDateFormat.format(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return strDate;
    }
    
    
    /**
     * 描述：获取指定日期时间的字符串,用于导出想要的格式.
     *
     * @param strDate String形式的日期时间，必须为yyyy-MM-dd HH:mm:ss格式
     * @param format  输出格式化字符串，如："yyyy-MM-dd HH:mm:ss"
     * @return String 转换后的String类型的日期时间
     */
    public static String getStringByFormat(String strDate, String format) {
        String mDateTime = null;
        try {
            Calendar c = new GregorianCalendar();
            SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
            c.setTime(mSimpleDateFormat.parse(strDate));
            SimpleDateFormat mSimpleDateFormat2 = new SimpleDateFormat(format);
            mDateTime = mSimpleDateFormat2.format(c.getTime());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mDateTime;
    }





    /** 
     * 得到几天前的时间 
     *  
     * @param d 
     * @param day 
     * @return 
     */  
    public static long getDateBefore(Date d, int day) {  
        Calendar now = Calendar.getInstance();  
        now.setTime(d);  
        now.set(Calendar.DATE, now.get(Calendar.DATE) - day); 
        Date date = now.getTime();
        return date.getTime();  
    }






    /**
     * 得到几天后的时间
     *
     * @param d
     * @param day
     * @return
     */
    public static long getDateAfter(Date d, int day) {
        Calendar now = Calendar.getInstance();
        now.setTime(d);
        now.set(Calendar.DATE, now.get(Calendar.DATE) + day);
        Date date = now.getTime();
        return date.getTime();
    }



    /**
     * 得到N小时后的时间
     *
     * @param d
     * @param hour
     * @return
     */
    public static long getHourAfter(Date d, int hour) {
        Calendar now = Calendar.getInstance();
        now.setTime(d);
        now.set(Calendar.HOUR, now.get(Calendar.HOUR) + hour);
        Date date = now.getTime();
        return date.getTime();
    }


    /**
     * 得到N年后的前一天
     *
     * @param d
     * @param years  年数
     * @return
     */
    public static long getDateBeforeYear(Date d, int years) {
        Calendar now = Calendar.getInstance();
        now.setTime(d);
        now.set(Calendar.YEAR,now.get(Calendar.YEAR) + years);
        now.set(Calendar.DATE, now.get(Calendar.DATE) - 1);
        Date date = now.getTime();
        return date.getTime();
    }


    /**
     * 描述：计算两个日期所差的天数.
     *
     * @param date1 第一个时间的毫秒表示
     * @param date2 第二个时间的毫秒表示
     * @return int 所差的天数
     */
    public static int getOffectDay(long date1, long date2) {
//        Calendar calendar1 = Calendar.getInstance();
//        calendar1.setTimeInMillis(date1);
//        Calendar calendar2 = Calendar.getInstance();
//        calendar2.setTimeInMillis(date2);
//        //先判断是否同年
//        int y1 = calendar1.get(Calendar.YEAR);
//        int y2 = calendar2.get(Calendar.YEAR);
//        int d1 = calendar1.get(Calendar.MONTH)+1;
//        int d2 = calendar2.get(Calendar.MONTH) +1;
//        int maxDays = 0;
//        int day = 0;
//        if (y1 - y2 > 0) {
//            maxDays = calendar2.getActualMaximum(Calendar.DAY_OF_YEAR);
//            day = d1 - d2 + (maxDays *(y1 - y2));
//        } else if (y1 - y2 < 0) {
//            maxDays = calendar1.getActualMaximum(Calendar.DAY_OF_YEAR);
//            day = d1 - d2 - (maxDays *(y1 - y2));
//        } else {
//            day = d1 - d2;
//        }
//        return day;
        long vf  = date1-date2;
        long bbb = vf/1000/60/60/24;
        return  (int)Math.abs(bbb);
    }
    
    /**
     * 描述：计算两个日期所差的小时数.
     *
     * @param date1 第一个时间的毫秒表示
     * @param date2 第二个时间的毫秒表示
     * @return int 所差的小时数
     */
    public static int getOffectHour(long date1, long date2) {
        Calendar calendar1 = Calendar.getInstance();
        calendar1.setTimeInMillis(date1);
        Calendar calendar2 = Calendar.getInstance();
        calendar2.setTimeInMillis(date2);
        int h1 = calendar1.get(Calendar.HOUR_OF_DAY);
        int h2 = calendar2.get(Calendar.HOUR_OF_DAY);
        int h = 0;
        int day = getOffectDay(date1, date2);
        h = h1 - h2 + day * 24;
        return h;
    }

    /**
     * 描述：计算两个日期所差的分钟数.
     *
     * @param date1 第一个时间的毫秒表示
     * @param date2 第二个时间的毫秒表示
     * @return int 所差的分钟数
     */
    public static int getOffectMinutes(long date1, long date2) {
        Calendar calendar1 = Calendar.getInstance();
        calendar1.setTimeInMillis(date1);
        Calendar calendar2 = Calendar.getInstance();
        calendar2.setTimeInMillis(date2);
        int m1 = calendar1.get(Calendar.MINUTE);
        int m2 = calendar2.get(Calendar.MINUTE);
        int h = getOffectHour(date1, date2);
        int m = 0;
        m = m1 - m2 + h * 60;
        return m;
    }
    
    
    /**
     * 描述：获取本周一.
     *
     * @param format the format
     * @return String String类型日期时间
     */
    public static String getFirstDayOfWeek(String format) {
        return getDayOfWeek(format, Calendar.MONDAY);
    }
    
    /**
     * 描述：获取本周的某一天.
     *
     * @param format        the format
     * @param calendarField the calendar field
     * @return String String类型日期时间
     */
    private static String getDayOfWeek(String format, int calendarField) {
        String strDate = null;
        try {
            Calendar c = new GregorianCalendar();
            SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
            int week = c.get(Calendar.DAY_OF_WEEK);
            if (week == calendarField) {
                strDate = mSimpleDateFormat.format(c.getTime());
            } else {
                int offectDay = calendarField - week;
                if (calendarField == Calendar.SUNDAY) {
                    offectDay = 7 - Math.abs(offectDay);
                }
                c.add(Calendar.DATE, offectDay);
                strDate = mSimpleDateFormat.format(c.getTime());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return strDate;
    }
    
    
    /**
     * 描述：获取本月第一天.
     *
     * @param format the format
     * @return String String类型日期时间
     */
    public static String getFirstDayOfMonth(String format) {
        String strDate = null;
        try {
            Calendar c = new GregorianCalendar();
            SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
            //当前月的第一天
            c.set(GregorianCalendar.DAY_OF_MONTH, 1);
            strDate = mSimpleDateFormat.format(c.getTime());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return strDate;
    }

    /**
     * 描述：获取本月最后一天.
     *
     * @param format the format
     * @return String String类型日期时间
     */
    public static String getLastDayOfMonth(String format) {
        String strDate = null;
        try {
            Calendar c = new GregorianCalendar();
            SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
            // 当前月的最后一天
            c.set(Calendar.DATE, 1);
            c.roll(Calendar.DATE, -1);
            strDate = mSimpleDateFormat.format(c.getTime());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return strDate;
    }
    
    
    /**
     * 描述：判断是否是闰年()
     * <p>(year能被4整除 并且 不能被100整除) 或者 year能被400整除,则该年为闰年.
     *
     * @param year 年代（如2012）
     * @return boolean 是否为闰年
     */
    public static boolean isLeapYear(int year) {
        if ((year % 4 == 0 && year % 400 != 0) || year % 400 == 0) {
            return true;
        } else {
            return false;
        }
    }
    
    
 
    
    
    /**
     * 取指定日期为星期几
     *
     * @param strDate  指定日期
     * @param inFormat 指定日期格式
     * @return String   星期几
     */
    public static String getWeekNumber(String strDate, String inFormat) {
        String week = "星期日";
        Calendar calendar = new GregorianCalendar();
        DateFormat df = new SimpleDateFormat(inFormat);
        try {
            calendar.setTime(df.parse(strDate));
        } catch (Exception e) {
            return "错误";
        }
        int intTemp = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        switch (intTemp) {
            case 0:
                week = "星期日";
                break;
            case 1:
                week = "星期一";
                break;
            case 2:
                week = "星期二";
                break;
            case 3:
                week = "星期三";
                break;
            case 4:
                week = "星期四";
                break;
            case 5:
                week = "星期五";
                break;
            case 6:
                week = "星期六";
                break;
        }
        return week;
    }

    
    /**
     * 取指定日期为星期几(返回英文)
     *
     * @param strDate  指定日期
     * @param inFormat 指定日期格式
     * @return String   星期几
     */
    public static String getWeekNumberToEn(String strDate, String inFormat) {
        String week = "Sunday";
        Calendar calendar = new GregorianCalendar();
        DateFormat df = new SimpleDateFormat(inFormat);
        try {
            calendar.setTime(df.parse(strDate));
        } catch (Exception e) {
            return "error";
        }
        int intTemp = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        switch (intTemp) {
            case 0:
                week = "Sunday";
                break;
            case 1:
                week = "Monday";
                break;
            case 2:
                week = "Tuesday";
                break;
            case 3:
                week = "Wednesday";
                break;
            case 4:
                week = "Thursday";
                break;
            case 5:
                week = "Friday";
                break;
            case 6:
                week = "Saturday";
                break;
        }
        return week;
    }
    
   
    
 

    /**
     * 根据用户生日计算年龄
     */
    public static int getAgeByBirthday(Date birthday) {
        Calendar cal = Calendar.getInstance();

        if (cal.before(birthday)) {
            throw new IllegalArgumentException(
                    "The birthDay is before Now.It's unbelievable!");
        }

        int yearNow = cal.get(Calendar.YEAR);
        int monthNow = cal.get(Calendar.MONTH) + 1;
        int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH);

        cal.setTime(birthday);
        int yearBirth = cal.get(Calendar.YEAR);
        int monthBirth = cal.get(Calendar.MONTH) + 1;
        int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH);

        int age = yearNow - yearBirth;

        if (monthNow <= monthBirth) {
            if (monthNow == monthBirth) {
                // monthNow==monthBirth
                if (dayOfMonthNow < dayOfMonthBirth) {
                    age--;
                }
            } else {
                // monthNow>monthBirth
                age--;
            }
        }
        return age;
    }

    /**
     * 友好显示时间差
     *
     * @param diff 毫秒
     * @return
     */
    public static String getFriendTimeOffer(long diff) {
        int day = (int) (diff / (24 * 60 * 60 * 1000));
        if (day > 0)
            return day + "天";
        int time = (int) (diff / (60 * 60 * 1000));
        if (time > 0)
            return time + "小时";
        int min = (int) (diff / (60 * 1000));
        if (min > 0)
            return min + "分钟";
        int sec = (int) diff / 1000;
        if (sec > 0)
            return sec + "秒";
        return "1秒";
    }

    /**
     * 友好的时间间隔
     *
     * @param duration 秒
     * @return
     */
    public static String getFriendlyDuration(long duration) {
        String str = "";
        long tmpDuration = duration;
        str += (tmpDuration / 60 > 10 ? tmpDuration / 60 : "0" + tmpDuration / 60) + ":";
        tmpDuration %= 60;
        str += (tmpDuration / 1 >= 10 ? tmpDuration / 1 : "0" + tmpDuration / 1);
        tmpDuration %= 1;
        return str;
    }
    
    /**
     * 友好的时间间隔2
     *
     * @param duration 秒
     * @return
     */
    public static String getFriendlyDuration2(long duration) {
        String str = "";
        long tmpDuration = duration;
        str += (tmpDuration / 60>0?tmpDuration / 60+"'":"");
        tmpDuration %= 60;
        str += (tmpDuration / 1>=10?tmpDuration / 1+"''":"0"+tmpDuration / 1+"''");
        tmpDuration %= 1;
        return str;
    }
    
    
    
    
    
    public static long formatDate2(String dateStr) {
		Date d = null;
		try {
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			d = Date1(sf.parse(dateStr));
		} catch (Exception e) {

		}
		return d.getTime();
	}

    public static long formatDate3(String dateStr) {
        Date d = null;
        try {
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
            d = Date1(sf.parse(dateStr));
        } catch (Exception e) {

        }
        return d.getTime();
    }




    public static long formatDate_5(String dateStr) {
        Date d = null;
        try {
            SimpleDateFormat sf = new SimpleDateFormat("yyyy.MM.dd");
            d = Date1(sf.parse(dateStr));
        } catch (Exception e) {

        }
        return d.getTime();
    }


    public static long formatDate4(String dateStr) {
        Date d = null;
        try {
            SimpleDateFormat sf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
            d = Date1(sf.parse(dateStr));
        } catch (Exception e) {

        }
        return d.getTime();
    }




    public static long formatDate5(String dateStr) {
        Date d = null;
        try {
            SimpleDateFormat sf = new SimpleDateFormat("MM-dd");
            d = Date1(sf.parse(dateStr));
        } catch (Exception e) {

        }
        return d.getTime();
    }


	private static Date Date1(Date date) {
		Date dateTime;
		dateTime = new java.sql.Date(date.getTime());
		return dateTime;
	}
    
    
    /** 
     * 日期格式字符串转换成时间戳 
     * @param
     * @param format 如：yyyy-MM-dd HH:mm:ss 
     * @return 
     */  
    public static long date2TimeStamp(String date_str,String format){  
        try {  
            SimpleDateFormat sdf = new SimpleDateFormat(format);  
            return sdf.parse(date_str).getTime();  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        return 0L;  
    }  
    
    
    
	public static long formatDate(String dateStr) {
		Date d = null;
		try {
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			d = Date1(sf.parse(dateStr));
		} catch (Exception e) {

		}
		return d.getTime();
	}





	  /** 
     * 使用预设格式将字符串转为Date 
	 * @throws ParseException 
     */  
    public  static Date parse(String strDate){  
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss");
    	Date date = null;
		try {
			date = sdf.parse(strDate);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return date;
    }


    
    /** 
     * 使用预设格式将字符串转为Date 
	 * @throws ParseException 
     */  
    public  static Date parse2(String strDate){  
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    	Date date = null;
		try {
			date = sdf.parse(strDate);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return date;
    }


    /**
     * 使用预设格式将字符串转为Date
     * @throws ParseException
     */
    public  static Date parsex(String strDate){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
        Date date = null;
        try {
            date = sdf.parse(strDate);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return date;
    }


    /**
     * 使用预设格式将字符串转为Date
     * @throws ParseException
     */
    public  static Date parse3(String strDate){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-d HH:MM:ss");
        Date date = null;
        try {
            date = sdf.parse(strDate);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return date;
    }
    
    
    /**
     * 通过日期来确定星座
     *
     * @param mouth
     * @param day
     * @return
     */
    public static String getStarSeat(int mouth, int day) {
        String starSeat = null;
        if ((mouth == 3 && day >= 21) || (mouth == 4 && day <= 19)) {
            starSeat = "白羊座";
        } else if ((mouth == 4 && day >= 20) || (mouth == 5 && day <= 20)) {
            starSeat = "金牛座";
        } else if ((mouth == 5 && day >= 21) || (mouth == 6 && day <= 21)) {
            starSeat = "双子座";
        } else if ((mouth == 6 && day >= 22) || (mouth == 7 && day <= 22)) {
            starSeat = "巨蟹座";
        } else if ((mouth == 7 && day >= 23) || (mouth == 8 && day <= 22)) {
            starSeat = "狮子座";
        } else if ((mouth == 8 && day >= 23) || (mouth == 9 && day <= 22)) {
            starSeat = "处女座";
        } else if ((mouth == 9 && day >= 23) || (mouth == 10 && day <= 23)) {
            starSeat = "天秤座";
        } else if ((mouth == 10 && day >= 24) || (mouth == 11 && day <= 22)) {
            starSeat = "天蝎座";
        } else if ((mouth == 11 && day >= 23) || (mouth == 12 && day <= 21)) {
            starSeat = "射手座";
        } else if ((mouth == 12 && day >= 22) || (mouth == 1 && day <= 19)) {
            starSeat = "摩羯座";
        } else if ((mouth == 1 && day >= 20) || (mouth == 2 && day <= 18)) {
            starSeat = "水瓶座";
        } else {
            starSeat = "双鱼座";
        }
        return starSeat;
    }
    
    /**
     * 两个日期比较
     * @param DATE1
     * @param DATE2
     * @return
     */
    public static int compare_date(String DATE1, String DATE2) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
        try {
            Date dt1 = df.parse(DATE1);
            Date dt2 = df.parse(DATE2);
            if (dt1.getTime() - dt2.getTime()>0) {//date1>date2
                return 1;
            } else {
                return -1;
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return 0;
    }
    
    
    
    public static long dateDiff(String startTime, String endTime, String format) {
        // 按照传入的格式生成一个simpledateformate对象
        SimpleDateFormat sd = new SimpleDateFormat(format);
        long nd = 1000 * 24 * 60 * 60;// 一天的毫秒数
        long nh = 1000 * 60 * 60;// 一小时的毫秒数
        long nm = 1000 * 60;// 一分钟的毫秒数
        long ns = 1000;// 一秒钟的毫秒数
        long diff;
        long day = 0;
        try {
            // 获得两个时间的毫秒时间差异
            diff = sd.parse(endTime).getTime()
                    - sd.parse(startTime).getTime();
            day = diff / nd;// 计算差多少天
            long hour = diff % nd / nh;// 计算差多少小时
            long min = diff % nd % nh / nm;// 计算差多少分钟
            long sec = diff % nd % nh % nm / ns;// 计算差多少秒
            // 输出结果
            //System.out.println("时间相差：" + day + "天" + hour + "小时" + min
            //        + "分钟" + sec + "秒。");
            if (day>=1) {
                  return day;
            }else {
                if (day==0) {
                    return 1;
                }else {
                    return 0;
                }
                
            }
          
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
        
    }
    
    
    /**
     * 获取N月后的今天
     * @param inputDate
     * @param number
     * @return
     */
    public static String  getAfterMonth(String inputDate,int number) {
        Calendar c = Calendar.getInstance();//获得一个日历的实例   
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");   
        Date date = null;   
        try{   
            date = sdf.parse(inputDate);//初始日期   
        }catch(Exception e){  

        }   
        c.setTime(date);//设置日历时间   
        c.add(Calendar.MONTH,number);//在日历的月份上增加6个月
        String strDate = sdf.format(c.getTime());//的到你想要得6个月后的日期   
        return strDate;
    }

    /**
     * 判断日期是不是 yyyy.mm.dd 格式
     * @param
     * @return
     */
    public static boolean isValidDate(String str) {
        String rexp1 = "^(^(\\d{4})(\\.)\\d{2}\\3\\d{1,2}$)";
        Pattern pattern = Pattern.compile(rexp1);
        Matcher matcher = pattern.matcher(str);
        if (matcher.find()){
            return true;
        }else{
            return false;
        }
    }

    /**
     * 判断日期是不是 yyyy.mm格式
     * @param str
     * @return
     */
    public static boolean isValidDate2(String str) {
        String rexp1 = "^(^(\\d{4})(\\.)\\d{2}$)";
        Pattern pattern = Pattern.compile(rexp1);
        Matcher matcher = pattern.matcher(str);
        if (matcher.find()){
            return true;
        }else{
            return false;
        }
    }


    public static void main(String[] args) {
//        boolean vv1= isValidDate("2021.03.02");
//        boolean vv2= isValidDate2("2021.04");
//        System.out.println(vv1);
//        System.out.println(vv2);


         String time1= "2021-08-04 13:00:00";
         String time2= "2021-08-03 15:00:00";
         long mm1 = formatDate(time1);
         long mm2 = formatDate(time2);

        int aa = getOffectDay(mm1,mm2);
        System.out.println(Math.abs(aa)+"天");


        long aaacc = 1652250876000L;





       String acaca =  TimeUtil.formatTime_One(aaacc);
        System.out.println(acaca);







    }



}
